package Negocio;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author asabido
 */
public class Profesional {
    
    private Integer ID;
    private String nombre;
    private String apellido;
    private String nick;
    private String password;
    private String email;
    private String telefono;

    public Profesional() {
    }

    public Integer getID() {
        return ID;
    }

    public void setID(Integer ID) {
        this.ID = ID;
    }

    /**
     * @return the nombre
     */
    public String getNombre() {
        return nombre;
    }

    /**
     * @param nombre the nombre to set
     */
    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    /**
     * @return the apellido
     */
    public String getApellido() {
        return apellido;
    }

    /**
     * @param apellido the apellido to set
     */
    public void setApellido(String apellido) {
        this.apellido = apellido;
    }

    /**
     * @return the nick
     */
    public String getNick() {
        return nick;
    }

    /**
     * @param nick the nick to set
     */
    public void setNick(String nick) {
        this.nick = nick;
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }

    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * @return the telefono
     */
    public String getTelefono() {
        return telefono;
    }

    /**
     * @param telefono the telefono to set
     */
    public void setTelefono(String telefono) {
        this.telefono = telefono;
    }

    public void getByID(Connection conn, int ID) {
         try
       {
           Statement stmt = conn.createStatement();
           ResultSet rset = stmt.executeQuery("SELECT * FROM `bysDB`.`Profesional` WHERE ID="+ID+";");
           
           if(rset.next()){
               this.ID = rset.getInt("ID");
               this.nombre = rset.getString("nombre");
               this.apellido = rset.getString("apellido");
               this.nick = rset.getString("nick");
               this.password = rset.getString("password");
               this.email = rset.getString("email");
               this.telefono = rset.getString("telefono");
           }
           if (rset !=null) rset.close();
           if (stmt != null) stmt.close();
           if (conn != null)conn.close();

        } catch (Exception e) {
            Logger.getLogger("Profesional").log(Level.SEVERE, "ERROR: " + e.getLocalizedMessage());
        }
    }
    
    public void getByNombre(Connection conn, String nombre) {
         try
       {
           Statement stmt = conn.createStatement();
           ResultSet rset = stmt.executeQuery("SELECT * FROM `bysDB`.`Profesional` WHERE nombre='"+nombre+"';");
           
           if(rset.next()){
               this.ID = rset.getInt("ID");
               this.nombre = rset.getString("nombre");
               this.apellido = rset.getString("apellido");
               this.nick = rset.getString("nick");
               this.password = rset.getString("password");
               this.email = rset.getString("email");
               this.telefono = rset.getString("telefono");
           }
           if (rset !=null) rset.close();
           if (stmt != null) stmt.close();
           if (conn != null)conn.close();

        } catch (Exception e) {
            Logger.getLogger("Profesional").log(Level.SEVERE, "ERROR: " + e.getLocalizedMessage());
        }
    }
    
    public List<Profesional> getAll(Connection conn) {
         try
       {
           Statement stmt = conn.createStatement();
           ResultSet rset = stmt.executeQuery("SELECT * FROM `bysDB`.`Profesional`");
           
           List<Profesional> profesionales = new ArrayList<Profesional>();
                      
           while(rset.next()){
               Profesional p = new Profesional();
               p.setID(rset.getInt("ID"));
               p.setNombre(rset.getString("nombre"));
               p.setApellido(rset.getString("apellido"));
               p.setNick(rset.getString("nick"));
               p.setPassword(rset.getString("password"));
               p.setEmail(rset.getString("email"));
               p.setTelefono(rset.getString("telefono"));
               profesionales.add(p);
           }
           if (rset !=null) rset.close();
           if (stmt != null) stmt.close();
           if (conn != null)conn.close();

           return profesionales;

        } catch (Exception e) {
            Logger.getLogger("Profesional").log(Level.SEVERE, "ERROR: " + e.getLocalizedMessage());
            return null;
        }
    }   
    
}
